home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (C) 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- /*------------------------------------------------------------------------------
- *
- * OORT - configure.c - Routines for configuring vehicle.
- *
- * $Id: configure.c,v 1.3 1994/01/28 00:16:53 mtj Exp $
- *
- * Chris Fouts - May, 1993.
- *
- *----------------------------------------------------------------------------*/
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <math.h>
- #include <string.h>
- #include <gl.h>
- #include <Performer/pf.h>
-
- #include "oort.h"
- #include "input.h"
- #include "sound.h"
- #include "configure.h"
- #include "dashboard.h"
- #include "text.h"
-
- #define N_BUTTONS 23
- #define N_OPTION_BUTTONS 18
-
- #define LABEL_TITLE 0
- #define LABEL_SHIELD 1
- #define LABEL_LASER 2
- #define LABEL_ENGINE 3
- #define LABEL_ECM 4
- #define LABEL_SOLAR 5
- #define LABEL_TRANSM 6
- #define N_LABELS 7
-
- #define SHIELD_BUTTON 0
- #define LASER_BUTTON 3
- #define ENGINE_BUTTON 6
- #define ECM_BUTTON 9
- #define SOLAR_BUTTON 12
- #define TRANSM_BUTTON 15
- #define TEAM_A_BUTTON 18
- #define TEAM_B_BUTTON 19
- #define TEAM_C_BUTTON 20
- #define TEAM_D_BUTTON 21
- #define OK_BUTTON 22
-
- #define MAX_ACCEL 5.0f
- #define SHIELD_FACTOR 1.0f
- #define LASER_FACTOR 1.0f
- #define ENGINE_FACTOR 0.125f
- #define ECM_FACTOR 1.0f
- #define SOLAR_FACTOR 1.0f
-
- static float enginePower[3] = { 0.8f, 1.0f, 1.2f } ;
- static float gearing[3] = { 0.8f, 1.0f, 1.2f } ;
- static float shieldCoeff[3] = { 1.0f, 1.2f, 1.4f } ;
- static float laserCoeff[3] = { 0.6f, 0.8f, 1.0f } ;
- static float engineCoeff[3] = { 1.0f, 1.2f, 1.4f } ;
- static float ecmTime[3] = { 10.0f, 30.0f, 60.0f } ;
- static float solarCoeff[3] = { 1.0f, 1.5f, 2.0f } ;
-
- static int shieldValue = 0 ;
- static int laserValue = 0 ;
- static int engineValue = 0 ;
- static int ecmValue = 0 ;
- static int solarValue = 0 ;
- static int transmValue = 1 ;
- static int doneValue = 0 ;
- static int teamValue = 0 ;
-
- float topSpeed = 1.0f ;
- float accelFactor ;
- float shieldFactor ;
- float laserFactor ;
- float engineRate ;
- float cloakRate ;
- float solarRate ;
-
-
-
- extern ViewPort mainVP ;
- extern GeoFont *helvFont ;
- extern int leftMouseHit ;
- extern float mouseX ;
- extern float mouseY ;
- extern int selfStatus ;
- extern pfVec3 teamColor[] ;
- extern Player player[] ;
- extern int numberPlayers ;
-
- static struct Button {
- float l ;
- float r ;
- float b ;
- float t ;
- float x ;
- float y ;
- int *property ;
- int value ;
- long hiColor ;
- long medColor ;
- long loColor ;
- long textColor ;
- int status ;
- GeoFont *gf ;
- char *text ;
- } button[N_BUTTONS] ;
-
- static struct Label {
- float x ;
- float y ;
- char *text ;
- GeoFont *gf ;
- } label[N_LABELS] ;
-
- static char *numberLabel[] = { "0", "1", "2" } ;
- static char *gearedLabel[] = { "L", "M", "H" } ;
- static char *teamLabel[] = { "A", "B", "C", "D" } ;
- static char *labelText[] = {
- "Vehicle Configuration",
- "Shields",
- "Laser",
- "Engine",
- "ECM",
- "Solar Panels",
- "Gearing",
- } ;
-
- static long hbc = 0x00a0b010 ;
- static long mbc = 0x00707010 ;
- static long lbc = 0x00304000 ;
- static long ahbc = 0x0010b0a0 ;
- static long ambc = 0x00107070 ;
- static long albc = 0x00004030 ;
-
- static float configStatusY ;
-
- /* BEGIN PROTOTYPES -S configure.c */
- static long darkerColor( long c ) ;
- static void drawButton( struct Button *b ) ;
- static void HSVtoRGB( pfVec3 hsv, pfVec3 rgb ) ;
- static long lighterColor( long c ) ;
- static long packedColor( pfVec3 v ) ;
- static void pressButton( void ) ;
- static void readyToLand( void ) ;
- static void RGBtoHSV( pfVec3 rgb, pfVec3 hsv ) ;
- static void setConfigFactors( void ) ;
- static void setTeamButtonColor( int nButton, int nTeam ) ;
- static void unpackedColor( long c, pfVec3 rgb ) ;
- /* END PROTOTYPES -S configure.c */
-
-
-
- /*------------------------------------------------------------------------------
- * Draw configuration screen.
- *----------------------------------------------------------------------------*/
- void
- drawConfigureScreen(
- pfChannel *channel,
- void *data
- )
- {
- int i ;
- float x ;
- float y ;
- int configPts ;
- char str[256] ;
- int teamCount[4] ;
-
- pfPushState();
- pfBasicState();
-
- /*
- * Get input.
- */
- grabInput() ;
-
- /*
- * Check for button presses.
- */
- if( leftMouseHit )
- {
- leftMouseHit = 0 ;
- pressButton() ;
- }
- else
- {
- }
-
- if( mainVP.right - mainVP.left > mainVP.top - mainVP.bottom )
- {
- y = mainVP.top - mainVP.bottom ;
- x = (float)( mainVP.right - mainVP.left ) / y ;
- y = 1.0f ;
- }
- else
- {
- x = mainVP.right - mainVP.left ;
- y = (float)( mainVP.top - mainVP.bottom ) / x;
- x = 1.0f ;
- }
-
- pfPushIdentMatrix() ;
- ortho2( -x, x, -y, y ) ;
-
- zfunction( ZF_ALWAYS ) ;
- zwritemask( 0x0 ) ;
- shademodel( GOURAUD ) ;
- cpack( 0x0 ) ;
- clear() ;
-
- cpack( 0x0000ffff ) ;
- for( i = 0 ; i < N_LABELS ; i++ )
- {
- positionText( label[i].x, label[i].y ) ;
- drawString( label[i].gf, label[i].text ) ;
- }
-
- for( i = 0 ; i < N_BUTTONS ; i++ )
- {
- drawButton( &(button[i]) ) ;
- }
-
- configPts = shieldValue + laserValue + engineValue + ecmValue +
- solarValue ;
- if( configPts > 4 )
- {
- cpack( 0x000000ff ) ;
- sprintf( str, "Maximum configuration points (4) exceeded." ) ;
- }
- else
- {
- cpack( 0x0000ff00 ) ;
- sprintf( str, "Configuration points available: %d",
- 4 - configPts ) ;
- }
- positionText( -0.5f * getStrWidth( label[1].gf, str ), configStatusY ) ;
- drawString( label[1].gf, str ) ;
-
- teamCount[0] = 0 ;
- teamCount[1] = 0 ;
- teamCount[2] = 0 ;
- teamCount[3] = 0 ;
- for( i = 0 ; i < numberPlayers ; i++ )
- {
- teamCount[player[i].team] += 1 ;
- }
- c3f( teamColor[teamValue] ) ;
- sprintf( str, "Team (A:%d B:%d C:%d D:%d)", teamCount[0], teamCount[1],
- teamCount[2], teamCount[3] ) ;
- positionText( label[1].x, button[TEAM_A_BUTTON].b ) ;
- drawString( label[1].gf, str ) ;
-
- pfPopMatrix() ;
-
- if( doneValue && button[OK_BUTTON].status == 0 )
- {
- if( configPts <= 4 )
- {
- readyToLand() ;
- }
- else
- {
- postNewMessage( "Too many configuration points used." );
- }
- doneValue = 0 ;
- button[OK_BUTTON].loColor = lbc ;
- button[OK_BUTTON].medColor = mbc ;
- button[OK_BUTTON].hiColor = hbc ;
- }
-
- zfunction( ZF_LEQUAL ) ;
- zwritemask( 0xffffffff ) ;
- pfPopState();
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Draw a 3D button.
- *----------------------------------------------------------------------------*/
- static void
- drawButton(
- struct Button *b
- )
- {
- long c ;
- float v[2] ;
- float d ;
- float e ;
-
- d = 0.15 * ( b->t - b->b ) ;
- e = 1.5f * d ;
-
- cpack( b->medColor ) ;
- bgntmesh() ;
- v[0] = b->l + d ; v[1] = b->b + d ; v2f( v ) ;
- v[0] = b->r - d ; v2f( v ) ;
- v[0] = b->l + d ; v[1] = b->t - d ; v2f( v ) ;
- v[0] = b->r - d ; v2f( v ) ;
- endtmesh() ;
-
- bgntmesh() ;
- cpack( b->loColor ) ;
- v[0] = b->l + e ; v[1] = b->b + d ; v2f( v ) ;
- v[0] = b->l + d ; v[1] = b->b ; v2f( v ) ;
- v[0] = b->r - e ; v[1] = b->b + d ; v2f( v ) ;
- v[0] = b->r - d ; v[1] = b->b ; v2f( v ) ;
-
- v[0] = b->r - d ; v[1] = b->b + e ; v2f( v ) ;
- v[0] = b->r ; v[1] = b->b + d ; v2f( v ) ;
- v[0] = b->r - d ; v[1] = b->t - e ; v2f( v ) ;
- v[0] = b->r ; v[1] = b->t - d ; v2f( v ) ;
-
- cpack( b->hiColor ) ;
- v[0] = b->r - e ; v[1] = b->t - d ; v2f( v ) ;
- v[0] = b->r - d ; v[1] = b->t ; v2f( v ) ;
- v[0] = b->l + e ; v[1] = b->t - d ; v2f( v ) ;
- v[0] = b->l + d ; v[1] = b->t ; v2f( v ) ;
-
- v[0] = b->l + d ; v[1] = b->t - e ; v2f( v ) ;
- v[0] = b->l ; v[1] = b->t - d ; v2f( v ) ;
- v[0] = b->l + d ; v[1] = b->b + e ; v2f( v ) ;
- v[0] = b->l ; v[1] = b->b + d ; v2f( v ) ;
-
- cpack( b->loColor ) ;
- v[0] = b->l + e ; v[1] = b->b + d ; v2f( v ) ;
- v[0] = b->l + d ; v[1] = b->b ; v2f( v ) ;
- endtmesh() ;
-
- cpack( b->textColor ) ;
- positionText( b->x, b->y ) ;
- drawString( b->gf, b->text ) ;
-
- if( b->status == 1 )
- {
- c = b->loColor ;
- b->loColor = b->hiColor ;
- b->hiColor = c ;
- b->status = 0 ;
- }
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Initialize the configuration screen structures.
- *----------------------------------------------------------------------------*/
- void
- initConfigureScreen(
- void
- )
- {
- int i ;
- float x ;
- float y ;
- float xStart ;
- float w ;
- float gap ;
- GeoFont *bf ;
- GeoFont *tf ;
- GeoFont *lf ;
-
- w = 0.13 ;
- gap = 0.05 ;
- xStart = -0.75f ;
-
- bf = copyFont( helvFont ) ;
- setFontSize( bf, 0.5f * w ) ;
-
- tf = copyFont( helvFont ) ;
- setFontSize( tf, 0.20f ) ;
-
- lf = copyFont( helvFont ) ;
- setFontSize( lf, w ) ;
-
- button[SHIELD_BUTTON+0].property = &shieldValue ;
- button[SHIELD_BUTTON+1].property = &shieldValue ;
- button[SHIELD_BUTTON+2].property = &shieldValue ;
-
- button[LASER_BUTTON+0].property = &laserValue ;
- button[LASER_BUTTON+1].property = &laserValue ;
- button[LASER_BUTTON+2].property = &laserValue ;
-
- button[ENGINE_BUTTON+0].property = &engineValue ;
- button[ENGINE_BUTTON+1].property = &engineValue ;
- button[ENGINE_BUTTON+2].property = &engineValue ;
-
- button[ECM_BUTTON+0].property = &ecmValue ;
- button[ECM_BUTTON+1].property = &ecmValue ;
- button[ECM_BUTTON+2].property = &ecmValue ;
-
- button[SOLAR_BUTTON+0].property = &solarValue ;
- button[SOLAR_BUTTON+1].property = &solarValue ;
- button[SOLAR_BUTTON+2].property = &solarValue ;
-
- button[TRANSM_BUTTON+0].property = &transmValue ;
- button[TRANSM_BUTTON+1].property = &transmValue ;
- button[TRANSM_BUTTON+2].property = &transmValue ;
-
- /*
- * Initialize button locations.
- */
- y = 0.75f ;
- for( i = 0 ; i < TRANSM_BUTTON ; i++ )
- {
- if( i % 3 == 0 )
- {
- x = xStart ;
- y = y - w - gap ;
- }
- else
- {
- x += w + gap ;
- }
- if( i % 3 == *(button[i].property) )
- {
- button[i].hiColor = ahbc ;
- button[i].medColor = ambc ;
- button[i].loColor = albc ;
- }
- else
- {
- button[i].hiColor = hbc ;
- button[i].medColor = mbc ;
- button[i].loColor = lbc ;
- }
- button[i].l = x ;
- button[i].r = x + w ;
- button[i].b = y ;
- button[i].t = y + w ;
-
- button[i].text = numberLabel[i%3] ;
- button[i].x = x + 0.5f *
- ( w - getStrWidth( bf, button[i].text ) ) ;
- button[i].y = y + 0.25f * w ;
-
- button[i].gf = bf ;
- button[i].value = i % 3 ;
- button[i].textColor = 0x00ffffff ;
- button[i].status = 0 ;
- }
-
- y -= 1.2f * w ;
- configStatusY = y ;
-
- x = xStart ;
- y -= 1.5f * w ;
- for( i = TRANSM_BUTTON ; i < TRANSM_BUTTON + 3 ; i++ )
- {
- if( i % 3 == *(button[i].property) )
- {
- button[i].hiColor = ahbc ;
- button[i].medColor = ambc ;
- button[i].loColor = albc ;
- }
- else
- {
- button[i].hiColor = hbc ;
- button[i].medColor = mbc ;
- button[i].loColor = lbc ;
- }
- button[i].l = x ;
- button[i].r = x + w ;
- button[i].b = y ;
- button[i].t = y + w ;
-
- button[i].text = gearedLabel[i%3] ;
- button[i].x = x + 0.5f *
- ( w - getStrWidth( bf, button[i].text ) ) ;
- button[i].y = y + 0.25f * w ;
-
- button[i].gf = bf ;
- button[i].value = i % 3 ;
- button[i].textColor = 0x00ffffff ;
- button[i].status = 0 ;
-
- x += w + gap ;
- }
-
- button[TEAM_A_BUTTON].property = &teamValue ;
- button[TEAM_B_BUTTON].property = &teamValue ;
- button[TEAM_C_BUTTON].property = &teamValue ;
- button[TEAM_D_BUTTON].property = &teamValue ;
-
- x = xStart ;
- y -= 1.5f * w ;
- for( i = TEAM_A_BUTTON ; i <= TEAM_D_BUTTON ; i++ )
- {
- setTeamButtonColor( i, i-TEAM_A_BUTTON ) ;
-
- button[i].l = x ;
- button[i].r = x + w ;
- button[i].b = y ;
- button[i].t = y + w ;
-
- button[i].text = teamLabel[i-TEAM_A_BUTTON] ;
- button[i].x = x + 0.5f *
- ( w - getStrWidth( bf, button[i].text ) ) ;
- button[i].y = y + 0.25f * w ;
-
- button[i].gf = bf ;
- button[i].value = i - TEAM_A_BUTTON ;
- button[i].textColor = 0x0 ;
- button[i].status = 0 ;
-
- x += w + gap ;
- }
-
- x = -w ;
- y -= 1.5f * w ;
- i = OK_BUTTON ;
- button[i].hiColor = hbc ;
- button[i].medColor = mbc ;
- button[i].loColor = lbc ;
- button[i].l = x ;
- button[i].r = x + 2.0f * w ;
- button[i].b = y ;
- button[i].t = y + w ;
-
- button[i].text = strdup( "Done" ) ;
- button[i].x = x + 0.5f *
- ( 2.0f * w - getStrWidth( bf, button[i].text ) ) ;
- button[i].y = y + 0.25f * w ;
-
- button[i].gf = bf ;
- button[i].value = 1 ;
- button[i].textColor = 0x00ffffff ;
- button[i].status = 0 ;
- button[i].property = &doneValue ;
-
- /*
- * Initialize labels.
- */
- y = 0.80f ;
- label[LABEL_TITLE].text = labelText[LABEL_TITLE] ;
- label[LABEL_TITLE].gf = tf ;
- label[LABEL_TITLE].x = -0.5f * getStrWidth( tf,
- labelText[LABEL_TITLE] ) ;
- label[LABEL_TITLE].y = y ;
-
- x = xStart + 4.0f * ( w + gap ) ;
-
- label[LABEL_SHIELD].text = labelText[LABEL_SHIELD] ;
- label[LABEL_SHIELD].gf = lf ;
- label[LABEL_SHIELD].x = x ;
- label[LABEL_SHIELD].y = button[SHIELD_BUTTON].b ;
-
- label[LABEL_LASER].text = labelText[LABEL_LASER] ;
- label[LABEL_LASER].gf = lf ;
- label[LABEL_LASER].x = x ;
- label[LABEL_LASER].y = button[LASER_BUTTON].b ;
-
- label[LABEL_ENGINE].text = labelText[LABEL_ENGINE] ;
- label[LABEL_ENGINE].gf = lf ;
- label[LABEL_ENGINE].x = x ;
- label[LABEL_ENGINE].y = button[ENGINE_BUTTON].b ;
-
- label[LABEL_ECM].text = labelText[LABEL_ECM] ;
- label[LABEL_ECM].gf = lf ;
- label[LABEL_ECM].x = x ;
- label[LABEL_ECM].y = button[ECM_BUTTON].b ;
-
- label[LABEL_SOLAR].text = labelText[LABEL_SOLAR] ;
- label[LABEL_SOLAR].gf = lf ;
- label[LABEL_SOLAR].x = x ;
- label[LABEL_SOLAR].y = button[SOLAR_BUTTON].b ;
-
- label[LABEL_TRANSM].text = labelText[LABEL_TRANSM] ;
- label[LABEL_TRANSM].gf = lf ;
- label[LABEL_TRANSM].x = x ;
- label[LABEL_TRANSM].y = button[TRANSM_BUTTON].b ;
-
- setConfigFactors() ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Check for clicking on buttons.
- *----------------------------------------------------------------------------*/
- static void
- pressButton(
- void
- )
- {
- int i ;
- int j ;
- int k ;
- long c ;
- float x ;
- float y ;
-
- for( i = 0 ; i < N_OPTION_BUTTONS ; i++ )
- {
- if( button[i].l <= mouseX && mouseX <= button[i].r &&
- button[i].b <= mouseY && mouseY <= button[i].t )
- {
- *(button[i].property) = button[i].value ;
- k = i - ( i % 3 ) ;
- for( j = 0 ; j < 3 ; j++ )
- {
- if( ( i % 3 ) == j )
- {
- button[k+j].status = 1 ;
- button[k+j].loColor = ahbc ;
- button[k+j].medColor = ambc ;
- button[k+j].hiColor = albc ;
- }
- else
- {
- button[k+j].loColor = lbc ;
- button[k+j].medColor = mbc ;
- button[k+j].hiColor = hbc ;
- }
- }
- if( shieldValue + laserValue + engineValue +
- ecmValue + solarValue > 4 )
- {
- sfx( SFX_NOT_OK ) ;
- }
- else
- {
- sfx( SFX_OK ) ;
- }
- }
- }
-
- for( i = N_OPTION_BUTTONS ; i < TEAM_D_BUTTON + 1 ; i++ )
- {
- if( button[i].l <= mouseX && mouseX <= button[i].r &&
- button[i].b <= mouseY && mouseY <= button[i].t )
- {
- *(button[i].property) = button[i].value ;
- c = button[i].loColor ;
- button[i].loColor = button[i].hiColor ;
- button[i].hiColor = c ;
- button[i].status = 1 ;
- player[SELF].team = i - TEAM_A_BUTTON ;
- sfx( SFX_OK ) ;
- }
- }
-
- for( i = TEAM_D_BUTTON + 1 ; i < N_BUTTONS ; i++ )
- {
- if( button[i].l <= mouseX && mouseX <= button[i].r &&
- button[i].b <= mouseY && mouseY <= button[i].t )
- {
- *(button[i].property) = button[i].value ;
- button[i].loColor = hbc ;
- button[i].medColor = mbc ;
- button[i].hiColor = lbc ;
- button[i].status = 1 ;
- sfx( SFX_OK ) ;
- }
- }
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Prepare to land.
- *----------------------------------------------------------------------------*/
- static void
- readyToLand(
- void
- )
- {
- selfStatus = OORT_ST_IN_ORBIT ;
- leftMouseHit = 0 ;
- setMainDrawFunction() ;
-
- setConfigFactors() ;
- }
-
-
-
-
- /*------------------------------------------------------------------------------
- * Set the various configuration factors.
- *----------------------------------------------------------------------------*/
- static void
- setConfigFactors(
- void
- )
- {
- topSpeed = MAX_SPEED * enginePower[engineValue] * gearing[transmValue] ;
- accelFactor = MAX_ACCEL * enginePower[engineValue] /
- gearing[transmValue] / gearing[transmValue] ;
- shieldFactor = SHIELD_FACTOR * shieldCoeff[shieldValue] ;
- laserFactor = LASER_FACTOR * laserCoeff[laserValue] ;
- engineRate = ENGINE_FACTOR * engineCoeff[engineValue] ;
- cloakRate = ECM_FACTOR / ecmTime[ecmValue] ;
- solarRate = SOLAR_FACTOR * solarCoeff[solarValue] ;
- player[SELF].team = teamValue ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Convert a vector color to a packed color.
- *----------------------------------------------------------------------------*/
- static long
- packedColor(
- pfVec3 v
- )
- {
- int i ;
- long c = 0 ;
-
- for( i = 2 ; i >= 0 ; i-- )
- {
- c = c << 8 ;
- c |= (unsigned int)( v[i] * 255.0f ) & 0x0ff ;
- }
-
- return( c ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Return a lighter color.
- *----------------------------------------------------------------------------*/
- static long
- lighterColor(
- long c
- )
- {
- pfVec3 rgb ;
- pfVec3 hsv ;
-
- unpackedColor( c, rgb ) ;
- RGBtoHSV( rgb, hsv ) ;
- hsv[2] += 0.2 ;
- if( hsv[2] > 1.0 ) {
- hsv[1] *= 0.75 ;
- hsv[2] = 1.0 ;
- }
- HSVtoRGB( hsv, rgb ) ;
- return( packedColor( rgb ) ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Return a darker color.
- *----------------------------------------------------------------------------*/
- static long
- darkerColor(
- long c
- )
- {
- pfVec3 rgb ;
- pfVec3 hsv ;
-
- unpackedColor( c, rgb ) ;
- RGBtoHSV( rgb, hsv ) ;
- hsv[2] -= 0.2 ;
- if( hsv[2] < 0.0 )
- return( 0 ) ;
- HSVtoRGB( hsv, rgb ) ;
- return( packedColor( rgb ) ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Unpack a color.
- *----------------------------------------------------------------------------*/
- static void
- unpackedColor(
- long c,
- pfVec3 rgb
- )
- {
- int i ;
-
- for( i = 0 ; i < 3 ; i++ )
- {
- rgb[i] = (float)( c & 0x0ff ) / 255.0f ;
- c = c >> 8 ;
- }
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Convert from HSV to RGB space.
- *----------------------------------------------------------------------------*/
- static void
- HSVtoRGB(
- pfVec3 hsv,
- pfVec3 rgb
- )
- {
- int i ;
- float f ;
- float p ;
- float q ;
- float t ;
-
- hsv[0] *= 360.0f ;
- if( hsv[1] == 0.0f )
- {
- rgb[0] = hsv[2] ;
- rgb[1] = hsv[2] ;
- rgb[2] = hsv[2] ;
- }
- else
- {
- if( hsv[0] == 360.0f )
- hsv[0] = 0.0f ;
- hsv[0] /= 60.0f ;
- i = floorf( hsv[0] ) ;
- f = hsv[0] - i ;
- p = hsv[2] * ( 1.0f - hsv[1] ) ;
- q = hsv[2] * ( 1.0f - ( hsv[1] * f ) ) ;
- t = hsv[2] * ( 1.0f - ( hsv[1] * ( 1.0f - f ) ) ) ;
- switch( i )
- {
- case 0 :
- rgb[0] = hsv[2] ;
- rgb[1] = t ;
- rgb[2] = p ;
- break ;
- case 1 :
- rgb[0] = q ;
- rgb[1] = hsv[2] ;
- rgb[2] = p ;
- break ;
- case 2 :
- rgb[0] = p ;
- rgb[1] = hsv[2] ;
- rgb[2] = t ;
- break ;
- case 3 :
- rgb[0] = p ;
- rgb[1] = q ;
- rgb[2] = hsv[2] ;
- break;
- case 4 :
- rgb[0] = t ;
- rgb[1] = p ;
- rgb[2] = hsv[2] ;
- break;
- case 5 :
- rgb[0] = hsv[2] ;
- rgb[1] = p ;
- rgb[2] = q ;
- break;
- }
- }
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Convert from RGB space to HSV space.
- *----------------------------------------------------------------------------*/
- static void
- RGBtoHSV(
- pfVec3 rgb,
- pfVec3 hsv
- )
- {
- float h ;
- float s ;
- float v ;
- float cmax ;
- float cmin ;
- float cdelta ;
- float rc ;
- float gc ;
- float bc ;
-
- /* find the cmax and cmin of r g b */
- cmax = rgb[0] ;
- cmin = rgb[0] ;
- cmax = ( rgb[1] > cmax ? rgb[1] : cmax ) ;
- cmin = ( rgb[1] < cmin ? rgb[1] : cmin ) ;
- cmax = ( rgb[2] > cmax ? rgb[2] : cmax ) ;
- cmin = ( rgb[2] < cmin ? rgb[2] : cmin ) ;
- v = cmax ;
- if( cmax != 0.0f )
- {
- s = ( cmax - cmin ) / cmax ;
- }
- else
- {
- s = 0.0f ;
- h = 0.0f ;
- }
- if( s == 0.0f )
- {
- h = -1.0f ;
- }
- else
- {
- cdelta = cmax - cmin ;
- rc = ( cmax - rgb[0] ) / cdelta ;
- gc = ( cmax - rgb[1] ) / cdelta ;
- bc = ( cmax - rgb[2] ) / cdelta ;
- if( rgb[0] == cmax )
- {
- h = bc - gc ;
- }
- else if( rgb[1] == cmax )
- {
- h = 2.0f + rc - bc ;
- }
- else
- {
- h = 4.0f + gc - rc ;
- }
- h = h * 60.0f ;
- if( h < 0.0f )
- h += 360.0f ;
- }
- hsv[0] = h / 360.0f ;
- hsv[1] = s ;
- hsv[2] = v ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Set a team selection button to the correct color.
- *----------------------------------------------------------------------------*/
- static void
- setTeamButtonColor(
- int nButton,
- int nTeam
- )
- {
- long c ;
-
- c = packedColor( teamColor[nTeam] ) ;
- button[nButton].hiColor = lighterColor( c ) ;
- button[nButton].medColor = c ;
- button[nButton].loColor = darkerColor( c ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Print out a message of the current configuration.
- *----------------------------------------------------------------------------*/
- void
- showConfiguration(
- void
- )
- {
- postNewMessage( "Shields:%d Laser:%d Engine:%d ECM:%d Solar:%d "
- "Gearing:%c Team:%c", shieldValue, laserValue,
- engineValue, ecmValue, solarValue, "LMH"[transmValue],
- "ABCD"[teamValue] ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Set the default configuration values.
- *----------------------------------------------------------------------------*/
- int
- setDefaultConfig(
- char *str
- )
- {
- int err ;
- char gear ;
- char team ;
-
- if( sscanf( str, "%d %d %d %d %d %c %c", &shieldValue, &laserValue,
- &engineValue, &ecmValue, &solarValue, &gear, &team ) != 7 )
- {
- err = 1 ;
- }
- else if( shieldValue < 0 || shieldValue > 2 ||
- laserValue < 0 || laserValue > 2 ||
- engineValue < 0 || engineValue > 2 ||
- ecmValue < 0 || ecmValue > 2 ||
- solarValue < 0 || solarValue > 2 ||
- ( gear != 'L' && gear != 'M' && gear != 'H' ) ||
- ( team != 'A' && team != 'B' && team != 'C' && team != 'D' ) )
- {
- err = 1 ;
- }
- else
- {
- transmValue = ( gear == 'L' ) ? 0 : ( ( gear == 'M' ) ? 1 : 2 );
- teamValue = team - 'A' ;
- err = 0 ;
- }
-
- if( err == 1 )
- {
- shieldValue = 0 ;
- laserValue = 0 ;
- engineValue = 0 ;
- ecmValue = 0 ;
- solarValue = 0 ;
- }
-
- return( err ) ;
- }
-
-